package com.lpgu.scan;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.core.type.filter.AssignableTypeFilter;
import org.springframework.data.repository.Repository;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * @author: lpgu
 * @describe:JpaBeanDefinitionRegisterPostProccessor
 * @createAt: 2022/1/5 22:59
 */
@Service
public class JpaBeanDefinitionRegisterPostProcessor implements BeanDefinitionRegistryPostProcessor {
    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        JpaClassBeanDefinitionScanner scanner = new JpaClassBeanDefinitionScanner(registry);
        scanner.addIncludeFilter(new AssignableTypeFilter(Repository.class));
        scanner.scan("com.lpgu.repositories");
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    }
}
